<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>我的客户-{$system['name']}后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/static/admin/css/global.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style>
        .filtrate-warp{
            margin-bottom: 10px;
        }
        .filtrate-warp .title{
            padding: 5px 12px 7px 12px;
            font-size: 14px;
            font-weight: normal;
            text-align: left;
            cursor: pointer;
            width: 90px;
            background-color: transparent!important;
            color: black!important;
        }
        .filtrate-warp .title:hover{
            color: black;
        }
        .filtrate-warp .flag{
            padding: 6px 12px 6px 12px;
            cursor: pointer;
        }
        .filtrate-warp .flag:hover{
            color: black;
        }
        .filtrate-warp .layui-badge:hover{
            color: white!important;
        }
    </style>
</head>
<body >
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field " >
        <legend>高级查询</legend>
        <div class="layui-card" style="box-shadow: none;margin-top: 10px">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="border-bottom: transparent;height: auto" >
                <div class="layui-form-item" style="text-align: left;padding-left: 20px;">
                    <div class="layui-inline">
                        <label class="layui-form-label">日期查询：</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" autocomplete="off" name="at_time" id="at_time" placeholder="请输入日期查询">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">客户级别：</label>
                        <div class="layui-input-inline">
                            <select name="kh_rank" id="kh_rank">
                                <option value="">请选择客户级别</option>
                                {volist name='khRankList' id='vo'}
                                <option value="{$vo.rank_name}">{$vo.rank_name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">客户状态：</label>
                        <div class="layui-input-inline">
                            <select name="kh_status" id="kh_status">
                                <option value="">请选择客户状态</option>
                                {volist name='khStatusList' id='vo'}
                                <option value="{$vo.status_name}">{$vo.status_name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="">地区：</label>
                        <div class="layui-input-inline">
                            <select name="xs_area">
                                <option value="">请选择地区</option>
                                <?php
$xs_areaLst=\think\facade\Db::name('crm_customer')->field('xs_area')->where('status','=',1)->where('xs_area','<>','')->group('xs_area')->select()->toArray();
                                ?>
                                {volist name='xs_areaLst' id='vo'}
                                <option value="{$vo.xs_area}">{$vo.xs_area}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">手机：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="phone" name="phone" placeholder="请输入手机号码" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label" style="">邮箱：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="email" name="email" placeholder="请输入查询邮箱" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">微信号：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="wechat" name="wechat" placeholder="请输入微信号" class="layui-input">
                        </div>
                    </div>


                    <div class="layui-inline">
                        <label class="layui-form-label" style="">客户名称：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="name" name="name" placeholder="请输入客户名称" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-inline" style="float: right;padding-bottom: 15px">
                    <button class="layui-btn layuiadmin-btn-list"  lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"  style="vertical-align: sub;"></i>查询数据
                    </button>
                </div>

            </div>
        </div>
    </fieldset>
    <table class="layui-table" id="table-list" lay-filter="table-list"></table>
</div>
<script type="text/html" id="action">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="follow"><i class="layui-icon">&#xe654;</i>写跟进</a>
    <?php if(auth('Client/alterPrUserPri')){ ?>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="alter"><i class="layui-icon">&#xe60e;</i>转移</a>
    <?php } ?>
    <a class="layui-btn  layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
    <?php  if(auth('Client/mydel')){ ?>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
    <?php } ?>

</script>


<script type="text/html" id="topBtn">
    <button type="button" class="layui-btn layui-btn-primary layui-btn-radius layui-btn-sm" id="add"><i class="layui-icon">&#xe608;</i>添加客户</button>
    <?php  if(auth('Client/myXlsUpload')){ ?>
    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm" id="toAll" style="margin-right: 10px"><i class="layui-icon">&#xe681;</i>导入客户</button>
    <?php } ?>
    <button type="button" class="layui-btn layui-btn-danger layui-btn-radius layui-btn-sm" id="moveGh" lay-event="moveGh"><i class="layui-icon">&#xe770;</i>移入公海</button>
    <?php if(auth('Client/alterPrUserPri')){ ?>
    <button type="button" class="layui-btn layui-btn-primary layui-btn-radius layui-btn-sm" id="alterAll" lay-event="alterAll"><i class="layui-icon">&#xe60e;</i>转移客户</button>
    <?php } ?>
</script>
{include file="common/foot"/}
<script>
    layui.use(['easyadmin','table','form','upload','util','laydate'], function() {
        var table = layui.table,form = layui.form,laydate = layui.laydate, $ = layui.jquery,upload = layui.upload,util = layui.util,ea=layui.easyadmin;
        ea.listen();
        var tableIn = table.render({
            elem: '#table-list',
            url: '{:url("perClilist")}',
            method: 'post',
            toolbar: '#topBtn',
            defaultToolbar:['filter',{
                title: '导入模板下载',
                layEvent: 'import_template',
                icon: 'layui-icon-template',
            }],
            page: true,
            cols: [[
                {checkbox:true,fixed: true},
                {field: 'id', title: 'ID',  fixed: true,hide:true},
                {field: 'name', title: '客户名称',templet:function (res) {
                        return "<a href='{:url('dialogue')}?id="+res.id+"'>"+res.name+"</a>";
                    }},
                {field: 'xs_area', title: '地区' },
                {field: 'phone', title: '联系号码' },
                {field: 'email', title: '邮箱' },
                {field: 'wechat', title: '微信号' },
                {field: 'kh_rank', title: '客户级别' },
                {field: 'kh_status', title: '客户状态' ,hide:true},
                {field: 'issuccess', title: '成交状态',templet:function (res) {
                        var issuccess = res.issuccess;
                        if (issuccess == 1) {
                             return '已成交';
                        }else{
                            return '未成交';
                        }
                    } ,hide:true},
                {field: 'last_up_records', title: '最新跟进记录', },
                {field: 'last_up_time', title: '最近跟进时间',hide:true },
                 {field: 'next_up_time', title: '下次跟进时间',hide:true },
                {field: 'kh_hangye', title: '客户来源',hide:true},
                {field: 'pr_user', title: '负责人',hide:false },
                {field: 'pr_gh_type', title: '所属公海',hide:true },
                {field: 'to_gh_time', title: '划入公海时间',hide:true },
                {field: 'ut_time', title: '更新于',hide:true},
                {field: 'remark', title: '备注'},
                {field: 'at_time', title: '创建时间', },
                {field: 'at_user', title: '创建人',hide:true},
                {field: 'pr_user_bef', title: '前负责人',hide:true },
                {width: 320, align: 'center', toolbar: '#action'}
            ]],
            limit: {$system['more']['admin_pagesize']} //每页默认显示的数量
            ,done: function (res, curr, count) {
                var that = this.elem.next();
            }
        });
        $('body').on('click','#add',function() {
            ea.open('添加客户',"{:url('Client/add')}");
        })

        //将上述表格示例导出为 csv 文件
        //table.exportFile(tableIn.config.id, data); //data 为该实例中的任意数量的数据
        //table.exportFile(id, data, type); //导出数据
        //监听事件
        table.on('toolbar(table-list)', function(obj){

            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data; //获取选中的数据
            switch(obj.event){
                case 'moveGh':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    // } else if(data.length > 1){
                    //     layer.msg('只能同时编辑一个');
                    } else {
                        //console.log(data);
                        alterList = [];  //定义需要转移的数组
                        data.forEach(function (obj,index) {
                            alterList.push(obj.id);
                        });
                        var currConfirm = layer.confirm('您确定这'+data.length+'个客户转入公海吗？',function (index) {
                            ea.open('移入公海',"{:url('Client/toMoveGh')}?ids="+alterList);
                        });
                    }
                    break;
                case 'alterAll':
                    var checkStatus = table.checkStatus(obj.config.id)
                        ,data=checkStatus.data;//获取选中的数据

                    if(data.length > 0){
                        alterList = [];  //定义需要转移的数组
                        data.forEach(function (obj,index) {
                            alterList.push(obj.id);
                        });

                        var currConfirm = layer.confirm('您确定要转移这'+data.length+'个客户吗？',function (index) {
                            layer.close(currConfirm);
                            ea.open('转移客户',"{:url('Client/alterPrUserPri')}?ids="+alterList);
                        });
                    }else {
                        layer.msg("请选择需要转移的客户");
                    }
                    break;
                case 'import_template':
                    window.open('/uploads/template/customer_template.xlsx','_blank');
            }
        });
        /*监听行内操作*/
        table.on('tool(table-list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'follow') {
                ea.open('客户跟进',"{:url('dialogue')}?id="+data.id,'100%','100%',function (){
                    $.post("{:url('leads/get')}",{id:data.id},function(res){
                        if(res.code===0){
                            obj.update(
                                res.data
                            );
                        }
                    });
                });
            } else if (obj.event === 'del') {
                layer.confirm('您确定要删除这个客户吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('del')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===0){
                            layer.msg(res.msg,{time:2000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg('操作失败！',{time:2000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
            else if(obj.event === 'edit'){
                ea.open('编辑客户',"{:url('Client/myedit')}?id="+data.id,null,null,function (){
                    $.post("{:url('leads/get')}",{id:data.id},function(res){
                        if(res.code===0){
                            obj.update(
                                res.data
                            );
                        }
                    });
                });
            }else if(obj.event === 'alter'){
                ea.open('转移客户',"{:url('Client/alterPrUserPri')}?ids="+data.id);
            }
        });


//监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            table.reload('table-list', {
                url:"{:url('Client/personClientSearch')}",
                where: {
                    keyword: data.field
                },
                page:{
                    curr:1
                }
            });


        });



        laydate.render({
            elem: '#at_time'
        });

        //批量导入
        var indexMsg;
        //上传xls文件
        upload.render({ //允许上传的文件后缀
            elem: '#toAll'
            ,url: "{:url('Client/myXlsUpload')}"
            ,accept: 'file' //普通文件
            ,field:'xlsFile'
            ,exts: 'xls|xlsx' //只允许上传压缩文件

            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                indexMsg = layer.msg('正在导入数据，请稍等...', {
                    icon: 16,
                    shade: 0.04,
                    time:false //取消自动关闭
                });
            }
            ,done: function(res){
                layer.close(indexMsg); //关闭信息框
                if (res.code == 0){
                    layer.msg(res.msg, {time: 2800, icon: 1}, function () {
                        location.reload()
                    });
                }else {
                    layer.msg(res.msg, {time: 2800, icon: 2});
                }
            }
            ,error: function(index, upload){
                layer.close(indexMsg); //关闭信息框
                layer.msg('系统繁忙，请稍后...', {time: 2800, icon: 1});
            }
        });
    });
</script>
</body>
</html>